package orm;


import orm.Convert;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Dbconf {
    private static Properties dbp =new Properties();

 static{
//     InputStream is  = new InputStream() {
//         @Override
//         public int read() throws IOException {
//             return 0;
//         }
//     }
     try {
         InputStream is = new FileInputStream("../p.properties");
         dbp.load(is);
         is.close();
     } catch (FileNotFoundException e) {
         e.printStackTrace();
     } catch (IOException e) {
         e.printStackTrace();
     }
 }

 public static String getConf(String k){
     return dbp.getProperty(k,"");
 }
    public static String getConf(String k,String v){
        return dbp.getProperty(k,v);
    }


    public static Integer getIntagerValue(String key) {
        return Integer.parseInt(dbp.getProperty(key, ""));
    }

    public static Integer getIntagerValue(String key, String defaultValue) {
        return Integer.parseInt(dbp.getProperty(key, defaultValue));
    }

    public static Double getDoubleValue(String key) {
        return Double.parseDouble(dbp.getProperty(key, ""));
    }

    public static Double getDoubleValue(String key, String defaultValue) {
        return Double.parseDouble(dbp.getProperty(key, defaultValue));
    }

    public static <T>T getObj(String k , Convert<T> convert){
      return convert.parse(dbp.getProperty(k,""));
    }

    public static <T>T getObj(String k ,String defV, Convert<T> convert){
        return convert.parse(dbp.getProperty(k,""));
    }
}
